package com.zc.framework.web.freemarker;

import com.zc.framework.spring.SpringContextHolder;
import freemarker.template.Configuration;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
import org.springframework.web.servlet.view.freemarker.FreeMarkerView;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;
import java.util.Set;

/**
 * Created by zc on 2016/12/15.
 */
public class FreeMarkerViewExtend  extends FreeMarkerView {

    @Override
    protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception {
        try {
            super.exposeHelpers(model, request);
        } catch (Exception e) {
            e.printStackTrace();
//            LoggerUtils.fmtError(FreeMarkerViewExtend.class,e, "FreeMarkerViewExtend 加载父类出现异常。请检查。");
        }
//        model.put(Constant.CONTEXT_PATH, request.getContextPath());

        Configuration configuration = super.getConfiguration();
        try {
            FreeMarkerConfigExtend.putInitShared(configuration);
        } catch (TemplateModelException e) {
            logger.error("添加Freemarker自定义方法失败;" ,e);
        }

//        model.putAll(Ferrmarker.initMap);
//        UUser token = TokenManager.getToken();
        //String ip = IPUtils.getIP(request);
//        model.put("token", token);//登录的token
//        model.put("_time", new Date().getTime());
//        model.put("NOW_YEAY", Constant.NOW_YEAY);//今年

//        model.put("_v", Constant.VERSION);//版本号，重启的时间
//        model.put("cdn", Constant.DOMAIN_CDN);//CDN域名
    }
}
